﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pampa.CRUD.Core
{
    public class TransactionAR : ITransaction
    {
        private readonly IActiveRecord _entity;
        private bool _closed;

        public TransactionAR(IActiveRecord entity)
        {
            _entity = entity;
            _closed = false;
        }

        public void Commit()
        {
            _entity.CommitTransaction();
            _closed = true;
        }

        public void Rollback()
        {
            _entity.RollBackTransaction();
            _closed = true;
        }

        public void Dispose()
        {
            if(!_closed)
            {
                _entity.RollBackTransaction();
            }
        }
    }
}
